<?php
require_once './BaiDuCommon.php';
require_once './BaiDuStoreSvc.php';
require_once './BaiDuProductSvc.php';
require_once './BaiDuCategorySvc.php';
class Demo extends BaiDuCommon
{
    public function start()
    {
        /*$ticket = $this->createTicket();

        $params = array(
            "cmd" => "shop.create",
            "timestamp" => 1430719064,
            "version" => 2,
            "ticket" => "CBB291F6-33BE-57CC-8FE3-441FE6E7BA6C",
            "source" => "test_source",
            "body" => array(
                "shop_id" => 123456,
                "name" => "测试商户"
            ),
            "secret" => "test_secret",
        );

        $sing = $this->createSign($params);*/

        $CategorySvc = new BaiDuCategorySvc();
        $ProductSvc = new BaiDuProductSvc();
        $StoreSvc = new BaiDuStoreSvc();

        $shop_id = "3";

        /*
        $openCategoryData = $CategorySvc->openCategory($shop_id);

        $res = $CategorySvc->sendOpenCategory($openCategoryData);*/

        /*
        $openCategoryData = $CategorySvc->closeCategory($shop_id);

        $res = $CategorySvc->sendCloseCategory($openCategoryData);*/

        //1 150638683125507
        //2 150638692325650
        /*$addCategoryData = $CategorySvc->addCategory($shop_id, 150638683125507, "感冒药", 1);

        //$res = $CategorySvc->sendAddCategory($addCategoryData);*/

        $category_id = "150638687525583";

        /*

        $updateCategory = $CategorySvc->updateCategory($shop_id, $category_id, "提拉喜欢", 2);
        //$res = $CategorySvc->sendUpdateCategory($updateCategory);*/

        
        
        /*$getCategory = $CategorySvc->getCategory($shop_id);
        $res = $CategorySvc->sendGetCategory($getCategory);*/

        /*$delCategory = $CategorySvc->delCategory($shop_id, $category_id);

        //$res = $CategorySvc->sendDelCategory($delCategory);

        echo json_encode($delCategory)."\n";exit;*/

        /*$photo = array(
            $ProductSvc->createPhoto("http://img.jsqq.net/uploads/allimg/150210/1-150210161I90-L.jpg", 1),
            $ProductSvc->createPhoto("http://img4.imgtn.bdimg.com/it/u=1762973822,121126736&fm=27&gp=0.jpg", 0),
            $ProductSvc->createPhoto("http://img1.2345.com/duoteimg/qqTxImg/11/2012091910313510745.jpg", 0),
        );

        //1 150638683125507
        //2 150638692325650
        $upc = "ABCDEFG1234567";
        $name = "提拉大力丸";
        $status = 1;
        $desc = "大力丸贼好吃";
        $sale_price = 1000;

        $addProdcutData = $ProductSvc->addProduct($shop_id, $upc, $name, $status, $desc, $sale_price, $photo);

        $res = $ProductSvc->sendAddProduct($addProdcutData);

        echo json_encode($res, JSON_UNESCAPED_UNICODE)."\n";exit;*/

        $product_id = "1506667948123830";

        
        /*$name = "提拉大力丸1";
        $status = "1";
        $desc = "大力丸贼好吃1";
        $sale_price = 10000;

        $updateProdcutData = $ProductSvc->updateProduct($shop_id, $product_id, $name, $status, $desc, $sale_price, $photo);

        //$res = $ProductSvc->sendUpdateProduct($updateProdcutData);
        echo json_encode($updateProdcutData)."\n";exit;*/

        /*$offLineData = $ProductSvc->offlineProduct($shop_id, $product_id);
        $res = $ProductSvc->sendOfflineProduct($offLineData);*/

        /*$onLineData = $ProductSvc->onlineProduct($shop_id, $product_id);
        //$res = $ProductSvc->sendOnlineProduct($offLineData);
        echo json_encode($onLineData)."\n";exit;*/
        /*$stocks = sprintf("%s:%s", $product_id, "1500");

        $updateStockBatch = $ProductSvc->updateStockBatch($shop_id, $stocks);

        //$res = $ProductSvc->sendUpdateStockBatch($updateStockBatch);
        echo json_encode($updateStockBatch)."\n";exit;*/
        /*$price = sprintf("%s:%s", $product_id, "1500");

        $updatePriceBatch = $ProductSvc->updatePriceBatch($shop_id, $price);

        //$res = $ProductSvc->sendUpdatePriceBatch($updatePriceBatch);
        echo json_encode($updatePriceBatch)."\n";exit;*/
        /*$p = 1;
        $productListData = $ProductSvc->productList($shop_id, $p);
        //$res = $ProductSvc->sendProductList($productListData);
        echo json_encode($productListData)."\n";exit;*/
        /*$category_id = '150665039329190';
        $bindCategoryData = $ProductSvc->bindCategory($shop_id, $product_id, $category_id);
        $res = $ProductSvc->sendBindCategory($bindCategoryData);

        var_dump($res);exit;*/

        /*$key = "药品";
        $brandListData = $ProductSvc->brandList($key);
        //$res = $ProductSvc->sendBrandList($brandListData);
        echo json_encode($brandListData)."\n";exit;*/


        $shopListData = $StoreSvc->shopList();
        $res = $StoreSvc->sendShopList($shopListData);

        var_dump($res);exit;

        

        /*$getShopInfoData = $StoreSvc->getShopInfo($shop_id);
        //$res = $StoreSvc->sendGetShopInfo($getShopInfoData);

        echo json_encode($getShopInfoData)."\n";exit;*/

        //药店基础信息
        /*$shop_id = 19921116;
        $name = "提拉的小药铺";
        $shop_logo = "https://appkfsypic.oss-cn-beijing.aliyuncs.com/2017092615263146540_700_700_.jpeg";
        $phone = "15834941000";
        $service_phone = "15834941000";

        $baseInfo = $StoreSvc->setBaseInfo($shop_id, $name, $shop_logo, $phone, $service_phone);



        //药店地址信息
        $province = "北京市";
        $city = "北京市";
        $county = "海淀区";
        $address = "北京市海淀区苏州街长远天地大厦A1座4202";

        $lng = 116.417618;
        $lat = 40.078363;
        $cityInfo = $StoreSvc->setCityInfo($province, $city, $county, $address, $lng, $lat);

        

        //药店营业时间
        $start = "06:00";
        $end = "21:30";
        $businessTime = $StoreSvc->setBusinessTime($start, $end);

        //药店经营范围
        $storeCategory = $StoreSvc->getCategorys();
        

        //获取扩展参数
        $extendedInfo = $StoreSvc->getExtendedInfo();


        $regionPoint = array(
            $StoreSvc->setRegionPoint(116.360256, 40.028947),
            $StoreSvc->setRegionPoint(116.342887, 40.051206),
            $StoreSvc->setRegionPoint(116.37198, 40.057577),
            $StoreSvc->setRegionPoint(116.393318, 40.062725),
            $StoreSvc->setRegionPoint(116.360256, 40.028947),
            $StoreSvc->setRegionPoint(116.342887, 40.051206),
            $StoreSvc->setRegionPoint(116.37198, 40.057577),
            $StoreSvc->setRegionPoint(116.393318, 40.062725)
        );

        $delivery_time = 60;
        $delivery_fee = 0;
        $regionInfo = $StoreSvc->setRegionInfo($city, $county, $delivery_time, $delivery_fee, $regionPoint);

        $addStoreInfoData = $StoreSvc->addShopInfo(
            $baseInfo, 
            $cityInfo, 
            $businessTime, 
            $storeCategory, 
            $extendedInfo, 
            $regionInfo
        );

        

        //$res = $StoreSvc->sendAddShopInfo($addStoreInfoData);

        $updateStoreInfoData = $StoreSvc->updateShopInfo(
            $baseInfo, 
            $cityInfo, 
            $businessTime, 
            $storeCategory, 
            $extendedInfo, 
            $regionInfo
        );*/

        //$res = $StoreSvc->sendUpdateShopInfo($updateStoreInfoData);

        /*$offlineData = $StoreSvc->offlineShop($shop_id);
        //$res = $StoreSvc->sendOffLineShop($offlineData);*/
        
        /*$openData = $StoreSvc->openShop($shop_id);
        //$res = $StoreSvc->sendOpenShop($openData);*/
        
        /*$closeData = $StoreSvc->closeShop($shop_id);
        $res = $StoreSvc->sendCloseShop($closeData);*/

        /*$content = "提拉最帅了";
        $setShopTopicData = $StoreSvc->setShopTopic($shop_id, $content);
        echo json_encode($setShopTopicData)."\n";exit;
        $res = $StoreSvc->sendSetShopTopic($setShopTopicData);
        var_dump($res);*/
    }
}

$Demo = new Demo();
$Demo->start();
?>